package com.service.impl;

import com.bean.entity.Role;
import com.bean.pojo.PageAssistant;
import com.dao.RoleMapper;
import com.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * User: 刘文雄
 * Date:2022/3/30 15:16
 *  身份表基础业务逻辑
 */
@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;
    @Override
    public int save(Role t) throws Exception {
        int insert = roleMapper.insert(t);
        if (insert==1) return 1;
        throw new Exception("新增身份信息失败");
    }
    @Override
    public int remove(Role t) throws Exception {
        int delete = roleMapper.delete(t);
        if (delete==1) return 1;
        throw new Exception("删除身份信息失败");
    }
    @Override
    public int modify(Role t) throws Exception {
        int update = roleMapper.update(t);
        if (update==1) return 1;
        throw new Exception("修改身份信息失败");
    }
    @Override
    public Role unique(Role t) throws Exception {
        List<Role> roleList = roleMapper.select(t);
        if (roleList.size() !=1) throw new Exception("无此身份信息");
        return roleList.get(0);
    }
    @Override
    public List<Role> query(Role t) {
        List<Role> roleList = roleMapper.select(t);
        return roleList;
    }
    @Override
    public PageAssistant<Role> queryByPage(Map<String, Object> map, PageAssistant<Role> pa) {

        //设置并查询总记录数
        pa.setCount(roleMapper.selectCount(map));
        //添加分页参数
        map.put("startCode", pa.getStartCode());
        map.put("pageSize", pa.getPageSize());

        //查询并设置页面内容
        pa.setItems(roleMapper.selectByPage(map));
        return pa;
    }
}
